package cn.com.taurus.controller.datatable;

import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.FundBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.Fund;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Controller
public class FundController {
    @Autowired
    FundBiz fundBiz;

    @RequestMapping("/fundOne")
    public String fundOne() {
        return "datatable/fund";
    }

    @RequestMapping("/updateFund")
    @Log(operation = "修改基金信息",type = 2)
    public String updateFundCompany(@ModelAttribute Fund fund){
        fundBiz.updateFund(fund);
        return "datatable/fund";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @param fId 基金编号
     * @param fName 基金名称
     * @param dwjz 单位净值
     * @param ifBuy 是否能够代销
     * @return
     */
    @ResponseBody
    @RequestMapping("/conditionSelectFund")
    @Log(operation = "条件查询基金信息",type = 1)
    public HashMap conditionSelectFund(Integer pageNum, Integer pageSize, String fId, String fName, String dwjz, String ifBuy){
        if (ifBuy.equals("不可交易")){
            ifBuy=null;
        }
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<Fund> rule = fundBiz.conditionSelectFund(fId,fName,dwjz,ifBuy);
        System.out.println(ifBuy);
        PageInfo<Fund> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectFundAll")
    public HashMap selectFundAll(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        System.err.println(pageNum+" "+pageSize);
        PageHelper.startPage(pageNum,pageSize);
        List<Fund> rule = fundBiz.selectAllFund();
        PageInfo<Fund> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        System.out.println(map);
        return map;
    }
}
